<?
msg("Draudimų sistema","Čia bus banai ir netik<hr><a href='".url('b,1')."'>Portu banai</a>");

//patikrinam r tikrai adminas ir ar tikrai i faila kreipesi taip kaip reikia
if (!defined("LEVEL") || LEVEL < 30 || !defined("OK")) { header('location: ../'); exit; }

//nustatom puslapiavimo puslapi, jei toks yra
if (isset($url['p']) && isnum($url['p']) && $url['p'] > 0) { $p = escape(ceil((int)$url['p'])); } else { $p = 0; }

//nustatom puslapiavimo limita
$limit = 50;

//Nustatom pagal ka rusiuosim/lygiuosim
if (isset($url['o']) && !empty($url['o'])) {
	switch ($url['o']) {
		case "ID": {
			$order = "`id`";
			break;
		}
		case "Portas": {
			$order = "`portas`";
			break;
		}
		case "Veiksmas": {
			$order = "`veiksmas`";
			break;
		}
		case "Priežastis": {
			$order = "`priezastis`";
			break;
		}
		case "Kada": {
			$order = "`date`";
			break;
		}
		default: {
			$order = "`id`";
			break;
		}
	}
}
//nustatom mazejancia ar didejancia tvarka
if (isset($url['w']) && !empty($url['w'])) {
	switch ($url['w']) {
		case "d": {
			$order .= " DESC";
			break;
		}
		case "a": {
			$order .= " ASC";
			break;
		}
		default: {
			$order .= " ASC";
			break;
		}
	}
}
else { $order = "`id` DESC"; }

//porto patikrinimas/skanavimas
$sql = "SELECT `portas` FROM ban_portai ORDER BY id ASC";
$sql_result = mysql_query1($sql) or die ("Negaliu ivygdyti uzklausos." . mysql_error());
while ($row = mysql_fetch_assoc($sql_result)) {
	//$id = $row["id"];
	$port = $row["portas"];
	//$desc = $row["priezastis"];
	$fp = @fsockopen($_SERVER['REMOTE_ADDR'], $port, $errno, $errstr, 1);
	//$fp = @fsockopen($_SERVER['REMOTE_ADDR'], $port);
	//stream_set_timeout($fp, 1);
	if ($fp) {
		klaida("Rastas blogas portas", "Blokuotas portas: ".$port);
		flush();
		fclose($fp);
	}
}
mysql_free_result($sql_result);

//Irasom duomenis i duombaze
if (isset($_POST) && !empty($_POST)) {
	if (isset($_POST['Portai']) && $_POST['Portai'] == 'Saugoti') {
		unset($_POST['Portai']);
		mysql_query1(insert('ban_portai',$_POST));
		redirect('?id,46;a,21;b,1','header');
	}
}

//portu baninimas
if (isset($url['b']) && $url['b'] == 1) {
	$title = "Portų banai";		//Atvaizdavimo pavadinimas
	$viso = kiek("ban_portai");	//suskaiciuojam kiek isviso irasu
	$forma = array(
	"Form"=>array("action"=>"","method"=>"post","enctype"=>"","id"=>"","class"=>"","name"=>"port"),
	"Portas:"=>array("type"=>"text","value"=>input($_SERVER['REMOTE_PORT']),"name"=>"portas","style"=>"width:400px"),
	"Veiksmas:"=>array("type"=>"select","value"=>array("1"=>"Baninti","0"=>"Peradresuoti"),"name"=>"veiksmas"),
	"Priežastis:"=>array("type"=>"text","value"=>"","name"=>"priezastis","style"=>"width:400px"),
	""=>array("type"=>"submit","name"=>"Portai","value"=>"Saugoti")
	);
	$sql = "SELECT * FROM `ban_portai` ORDER BY $order LIMIT ".escape($p).",".$limit;
	$sql = mysql_query1($sql);
	//sukisam visus rezultatus i masyva, veliau pasinaudodami klase ji atvaizduosim lenteleje
	while($row = mysql_fetch_assoc($sql)) {
		$info[] = array(
		"ID"=> $row['id'],
		"Portas"=> $row['portas'],
		"Veiksmas"=>($row['veiksmas'] == 1?'<font color="red">Baninti</font>':'<font color="blue">Peradresuoti</font>'),
		"Priezastis"=> input(trimlink($row['priezastis'],120)),
		"Valdymas"=>"<button onclick=\"if (confirm('Ar tikrai nori ištrinti?')) window.location='".url("d,".$row['id']."")."'; else return false;\">X</button>"
		);
	}
}

//Hostu baninimas, pvz: antisecurity.org
if (isset($url['b']) && $url['b'] == 2) {
	$title = "Hostų banai";
	$forma = array(
	"Form"=>array("action"=>"","method"=>"post","enctype"=>"","id"=>"","class"=>"","name"=>"port"),
	"Hostas:"=>array("type"=>"text","value"=>input($conf['Pavadinimas']),"name"=>"Portas","style"=>"width:400px"),
	"Veiksmas:"=>array("type"=>"select","value"=>array("1"=>"Baninti","0"=>"Peradresuoti"),"selected"=>input($ban['Veiksmas']),"name"=>"Veiksmas"),
	"Priežastis:"=>array("type"=>"text","value"=>input($conf['Priezastis']),"name"=>"Copyright","style"=>"width:400px"),
	""=>array("type"=>"submit","name"=>"Hostas","value"=>"Saugoti")
	);
}

//IP baninimas
if (isset($url['b']) && $url['b'] == 3) {
	$title = "IP banai";
	$forma = array(
	"Form"=>array("action"=>"","method"=>"post","enctype"=>"","id"=>"","class"=>"","name"=>"port"),
	"IP:"=>array("type"=>"text","value"=>input($conf['Pavadinimas']),"name"=>"Portas","style"=>"width:400px"),
	"Veiksmas:"=>array("type"=>"select","value"=>array("1"=>"Baninti","0"=>"Peradresuoti"),"selected"=>input($ban['Veiksmas']),"name"=>"Veiksmas"),
	"Priežastis:"=>array("type"=>"text","value"=>input($conf['Priezastis']),"name"=>"Copyright","style"=>"width:400px"),
	""=>array("type"=>"submit","name"=>"Ip","value"=>"Saugoti")
	);
}

//Atvaizduojam info ir formas
if (isset($forma) && isset($title)) {
	include_once("class.php");
	$bla = new forma();
	echo $bla->form($forma,$title);
}

//nupiesiam lenteles/sarasus
if (isset($title) && isset($info)) {
	$bla = new Table();
	if ($viso > $limit) { lentele("Puslapiai:",puslapiai($p,$limit,$viso,10)); }
	lentele($title." - ".$viso,$bla->render($info));
	if ($viso > $limit) { lentele("Puslapiai:",puslapiai($p,$limit,$viso,10)); }
}
?>